package class_and_object.homework;

/**
 * 11.3
 * @author haomin
 * @date 2022/05/30 22:44
 **/
import java.util.Date;
public class Account {
    private int id = 0;
    private double balance = 0;
    private double annualInterestRate = 0;
    private Date dateCreated;
    public Account() {
        dateCreated = new Date();
    }
    public Account(int id, double balance) {
        this.id = id;
        this.balance = balance;
        dateCreated = new Date();
    }
    public int getId() {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    }
    public double getBalance() {
        return balance;
    }
    public void setBalance(double balance) {
        this.balance = balance;
    }
    public double getAnnualInterestRate() {
        return annualInterestRate;
    }
    public void setAnnualInterestRate(double annualInterestRate) {
        this.annualInterestRate = annualInterestRate;
    }
    public Date getDateCreated() {
        return dateCreated;
    }
    public void withDraw(double money) {
        balance -= money;
    }
    public void deposit(double money) {
        balance += money;
    }
    public String toString() {
        return "账户id为："+ id +" 余额为："+balance;
    }
}

class CheckingAccount extends Account{
    private int quota;
    private double Overdraft_amount;

    public CheckingAccount(){
    }
    public CheckingAccount(double balance, int quota) {
        setBalance(balance);
        this.quota = quota;
    }
    public double getOverdraft_amount() {
        return Overdraft_amount;
    }
    public int getQuota() {
        return quota;
    }
    public void withDraw(double money) {
        if(getBalance()-money<0) {
            if(Math.abs(getBalance()-money)>quota) {
                System.out.println("透支额度不足!");
            }
            else {
                System.out.println("已透支 "+Math.abs(getBalance()-money)+" 元");
                setBalance(getBalance()-money);
            }
            Overdraft_amount=Math.abs(getBalance()-money);
        }
        else
            setBalance(getBalance()-money);
    }
    public String toString() {
        return "账户id为："+getId()+"余额为："+getBalance();
    }
}


class SavingsAccount extends Account{
    private double interestRate;
    private double interest;

    public SavingsAccount() {
    }
    public SavingsAccount(double balance, double interestRate) {
        setBalance(balance);
        this.interestRate = interestRate;
    }
    public double getInterestRate() {
        return interestRate;
    }
    public double getInterest(int month) {
        return interest=this.getBalance()*interestRate*month/12;
    }
    public double getbalance() {
        return getBalance()+interest;
    }
    public String toString() {
        return "账户id为："+getId()+" 余额为："+getbalance();
    }
}
